# 定义DMRSType结构体
struct DMRSType
    DMRSCongfigurationType::Float64
    DMRSReferencePoints::String
    NumCDMGroupsWithoutData::Float64
    DMRSdownlinkR16::Bool
    DMRSTypeAPosition::Float64
    DMRSAdditionalPosition::Float64
    DMRSLength::Float64
    CustomSymbolSet::Matrix{Float64}
    DMRSPortSet::Float64
    NIDNSCID::Matrix{Float64}
    NISCID::Float64
    DMRSEnhancedR18::Bool
    CDMGroups::Float64
    DeltaShifts::Float64
    FrequencyWeights::Matrix{Float64}
    TimeWeights::Matrix{Float64}
    DMRSSubcarrierLocations::Matrix{Float64}
    CDMLengths::Matrix{Float64}
end

# 定义PTRSType结构体，包含图中所示的PTRS相关属性
struct PTRSType
    PTRSPortSet::Matrix{Float64}
    TimeDensity::Float64
    FrequencyDensity::Float64
    REOffset::String
end

# 定义ReservedConfig结构体
struct nrPDSCHReservedConfigType
    PRBSet::Vector{Float64}
    SymbolSet::Vector{Float64}
    Period::Vector{Float64}
end

# 初始化ReservedConfig实例
reserved_config_instance = nrPDSCHReservedConfigType([], [], [])

# 定义PDSCHConfig结构体
struct PDSCHConfig
    ReservedRE::Matrix{Float64}
    NID::Matrix{Float64}
    NSizeBWP::Matrix{Float64}
    NStartBWP::Matrix{Float64}
    Modulation::String
    ReservedPRB::nrPDSCHReservedConfigType
    PRBSetType::String
    VRBToPRBInterleaving::Bool
    VRBBundleSize::Float64
    DMRS::DMRSType
    PTRS::PTRSType
    NumLayers::Float64
    MappingType::String
    SymbolAllocation::Vector{Float64}
    PRBSet::Matrix{Float64}
    RNTI::Float64
    EnablePTRS::Bool
    EnableCodewords::Float64
end

# 定义扩展参数结构体
struct Extension
    W::Array{ComplexF64, 3}  # 使用ComplexF64表示复数类型
    PRGBundleSize::Float64
    TargetCodeRate::Float64
    XOverhead::Float64
end

# # 定义包含 PUSCH 配置和扩展参数的结构体
# struct PUSCH
#     Config::PUSCHConfig
#     Extension::Extension
# end

# 创建Extension结构体实例并赋值
extension_instance = Extension(
    zeros(ComplexF64, 1, 256, 26),  # 创建一个1x256x26的复数数组，初始值为0，可根据实际情况修改
    2,
    0.7539,
    0
)

function hMultiUserPDSCH(numLayers)
    # 创建一个基础的 DMRSType 实例，根据需求设置初始值
    base_dmrs = DMRSType(
        1,
        "CRB0",
        2,
        false,
        2,
        0,
        2,
        zeros(Float64, 0, 0),
        2.0,
        zeros(Float64, 0, 0),
        0,
        false,
        1,
        1,
        reshape([1, 1], 1, 2),  # 将一维数组转换为 1x2 矩阵
        reshape([1, 1], 1, 2),  # 将一维数组转换为 1x2 矩阵
        reshape([1, 3, 5, 7, 9, 11], 6, 1),  # 将一维数组转换为 6x1 矩阵
        reshape([1, 1], 1, 2)  # 将一维数组转换为 1x2 矩阵
    )
    # 创建一个基础的 PTRSType 实例，根据需求设置初始值
    base_ptrs = PTRSType(
        zeros(Float64, 0, 0),
        1,
        2,
        "00"
    )
    # 创建一个基础的 PDSCH 配置
    pdsch = PDSCHConfig(
        zeros(Float64, 0, 0),
        zeros(Float64, 0, 0),
        zeros(Float64, 0, 0),
        zeros(Float64, 0, 0),
        "64QAM",
        reserved_config_instance,
        "VRB",
        false,
        1.0,
        base_dmrs,
        base_ptrs,
        0,
        "A",
        [0, 10],
        reshape([0, 1, 2, 3, 8, 9, 12, 13, 14, 15, 18, 19, 22, 23, 26, 27, 28, 29, 32, 33, 36, 37, 40, 41, 42, 43, 46, 47, 50], 29, 1),
        0,
        false,
        0
    )
    # 创建扩展参数
    extension = Extension(
        zeros(ComplexF64, 1, 256, 26),
        2,
        772/1024,
        0
    )
    numUEs = length(numLayers)
    # 初始化 PDSCHs 数组
    PDSCHs = [(Config = pdsch, Extension = extension) for _ in 1:numUEs]

    for ue in 1:numUEs
        # 重新创建新的 PDSCHConfig 实例，更新 NumLayers 和 RNTI
        new_pdsch = PDSCHConfig(
            pdsch.ReservedRE,
            pdsch.NID,
            pdsch.NSizeBWP,
            pdsch.NStartBWP,
            pdsch.Modulation,
            pdsch.ReservedPRB,
            pdsch.PRBSetType,
            pdsch.VRBToPRBInterleaving,
            pdsch.VRBBundleSize,
            pdsch.DMRS,
            pdsch.PTRS,
            numLayers[ue],
            pdsch.MappingType,
            pdsch.SymbolAllocation,
            pdsch.PRBSet,
            ue,
            pdsch.EnablePTRS,
            pdsch.EnableCodewords
        )
        PDSCHs[ue] = (Config = new_pdsch, Extension = extension)
    end

    return PDSCHs
end

# 设定 numLayers
numLayers = [1, 4, 4, 2, 4]
PDSCHs = hMultiUserPDSCH(numLayers)
println(PDSCHs)